package ch.fhnw.qualiscan.application.pages;


import ch.fhnw.qualiscan.Config;
import ch.fhnw.qualiscan.application.models.DomainModel;
import ch.fhnw.qualiscan.application.models.SurveyModel;
import ch.fhnw.qualiscan.application.models.UserModel;
import ch.fhnw.qualiscan.application.pages.tabs.DashboardTab1;
import ch.fhnw.qualiscan.core.Page;
import ch.fhnw.qualiscan.core.db.pojos.User;

import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.TabSheet.Tab;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;

import eu.livotov.tpt.i18n.TM;
/**
 * @author Kevin Mettenberger
 *
 */
@SuppressWarnings("serial")
public class Dashboard extends Page {
	
	Label title;
	Label description;

	public VerticalLayout tab2;
	
	public Tab tab1;
	public DashboardTab1 TabComponent1;
	public UserModel userModel;
	public Table surveyTable;
	public SurveyModel surveyModel;
	public User user;
	public DomainModel domainModel;

	@Override
	public void initModelsAndHelpers() {
		userModel = new UserModel();
		surveyModel = new SurveyModel();
		domainModel = new DomainModel();
	}
	
	@Override
	public void buildLayout() {
		VerticalLayout dashboardWrap = new VerticalLayout();
		dashboardWrap.setMargin(false, false, true, false);
		dashboardWrap.setSpacing(true);
		
		title = textHelper.h1(TM.get("dashboard.title"));
		dashboardWrap.addComponent(title);
		
		addComponent(dashboardWrap);
		
		user = new User();
		user.setId(userSession.getId());
		
		TabComponent1 = new DashboardTab1(this);
		
        tab1 = tabSheet.addTab(TabComponent1, TM.get("dashboard.tab1.title"), null);
        tabSheet.addTab(Tab2(), TM.get("dashboard.tab2.title"), null);
        
        addComponent(tabSheet);
	}
	
	public VerticalLayout Tab2() {
		tab2 = new VerticalLayout();
		tab2.setMargin(true);
		tab2.setSpacing(true);
		
		tab2.addComponent(textHelper.p(TM.get("dashboard.tab2.desc")));
		
		Button newSurvey = new Button(TM.get("dashboard.tab2.button"));
		newSurvey.addListener(new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				urlLib.setPage("NewSurvey");
				event.getButton().setEnabled(false);
			}
		});
		newSurvey.setIcon(Config.ICON_ADD);
		
		tab2.addComponent(newSurvey);
		
		return tab2;
	}
	
	@Override
	public void setNeededPermissions() {
		neededPermissions.add("loggedIn");
	}

	@Override
	public void initComponents() {
		
	}

	@Override
	public void thirdParameterChanged(String thirdParameter) {

	}

}
